package com.bobamrz.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.bobamrz.domain.DocCatalog;
import com.bobamrz.domain.DocType;
import com.bobamrz.hibernate.HibernateUtil;

public class DocCatalogDAO {

	private Session session = HibernateUtil.getSessionFactory().getCurrentSession();
	
	public List<DocCatalog> getSuperDocCatalogList() {
		String hql = "FROM DocCatalog WHERE level=1";
		Query query = session.createQuery(hql);
		return query.list();
	}
	
	public DocCatalog getById(long id) {
		String hql = "FROM DocCatalog WHERE docCatalog="+id;
		Query query = session.createQuery(hql);
		List<DocCatalog> catalogs = query.list();
		if(catalogs.size()>0) {
			return catalogs.get(0);
		} else {
			return null;
		}
	}
	
	public void save(DocCatalog dc) {
		session.merge(dc);
	}
	
}
